<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

class ps_baokim {

    var $classname = "ps_baokim";
    
    function show_configuration() {
        global $VM_LANG;
        $db = new ps_DB();

        include_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
    ?>
    <table class="adminform">
    	<!-- Email đăng ký tài khoản tại BAOKIM.vn-->
       	<tr class="row0">
        <td><strong>Email nhận tiền tại Bảo Kim</strong></td>
            <td>
           <input type="text" name="business" class="inputbox" value="<?php  echo business ?>" />            </td>
            <td></td>
        </tr>
        
        <!-- Mã merchant -->
        <tr class="row1">
        <td><strong>Merchant ID</strong></td>
            <td>
                <input type="text" name="merchant_id" class="inputbox" value="<?php  echo merchant_id ?>" />            </td>
            <td></td>
        </tr>
        
        <!-- Mật khẩu API -->
        <tr class="row0">
        <td><strong>Mật khẩu giao tiếp</strong></td>
            <td>
                <input type="password" name="baokim_secure_pass" class="inputbox" value="<?php  echo baokim_secure_pass ?>" />            </td>
            <td></td>
       </tr> 
		 
		 <tr class="row0">
        <td><strong>Đường dẫn sau khi thanh toán xong</strong></td>
            <td>
                <input type="text" name="url_success" class="inputbox" value="<?php  echo url_success ?>" />            </td>
            <td></td>
       </tr> 
             
       <!-- URL -->
<input type="hidden" name="url_detail" class="inputbox" value="" />
<input type="hidden" name="url_cancel" class="inputbox" value="" />

      </table>
<?php
    }
    
    function has_configuration() {
      return true;
   }
   
   function configfile_writeable() {
      return is_writeable( CLASSPATH."payment/".$this->classname.".cfg.php" );
   }
   
   function configfile_readable() {
      return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" );
   }
   
   function write_configuration( &$d ) {
   	  $d['payment_type'] = intval( vmGet( $_REQUEST, "payment_type" ));
   
   	  $my_config_array = array(
                              "business" 				=> $d['business'],
                              "merchant_id" 			=> $d['merchant_id'],
                              "baokim_secure_pass" => $d['baokim_secure_pass'],
                              "url_success" 			=> $d['url_success'],
                              "url_detail" 			=> $d['url_detail'],
                              "url_cancel" 			=> $d['url_cancel'],
                            );
      $config = "<?php\n";
      $config .= "if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); \n\n";
      foreach( $my_config_array as $key => $value ) {
        $config .= "define ('$key', '$value');\n";
      }
      
      $config .= "?>";
  
      if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) {
          fputs($fp, $config, strlen($config));
          fclose ($fp);
          return true;
     }
     else
        return false;
   }
   
   function process_payment($order_number, $order_total, &$d) {
        return true;
    }
   
}
